home *** CD-ROM | disk | FTP | other *** search
Text File | 1988-01-18 | 24.2 KB | 1,099 lines | [TEXT/EDIT] |
- /*________________________________
- MS.c
-
- ________________________________
- OPTIONS B=token E=verb G=ASM H=ASM Src J=ASM Symb K=Debug Symb Z=No float
- ________________________________*/
- #Options +B +E -G -H -J +K +Z
- #asm
- .verbose
- #endasm
- #include "MyTools.p"
- #include "MS.h"
- /* In order to minimize extern declarations in calling programs
- int has been optioned to int - if you are typing int to shorts you
- are in big trouble! */
- //=========================
- MSConfig MSInit(confPtr)
- MSConfig *confPtr;
- //=========================
- BEGIN_FCT
- static MSConfig confPar;
- static int confFlg=FALSE;
- Handle theHdl;
-
- IF (confPtr AND NOT confFlg)
- THEN
- SysBeep(30);
- ExitToShell();
- ENDIF
-
- SWIT ((int)confPtr)
- CASE (NIL)
- IF ((theHdl=GetResource(_MSCFGTYP,0)) EQ NIL)
- THEN
- SysBeep(30);
- SysBeep(30);
- ExitToShell();
- ELSE
- confPar=**((MSConfig **)theHdl);
- confFlg=TRUE;
- ENDIF
- ENDCASE
- CASE (1)
- ENDCASE
- DEFCASE
- confPar=*confPtr;
- ENDCASE
- ENDSWIT
-
- return ( confPar );
-
-
- END_FCT
- //=========================
- int MSMake(menuID, MIVTFct1,MIVTFct2)
- short menuID;
- int MIVTFct1;
- int MIVTFct2;
- //=========================
- BEGIN_FCT
-
- MSHdl theMSH;
- MSPtr theMSP;
- MenuVerb theMV, theMF;
- Handle theHdl;
- long defVal;
- int i,j;
- short dynamCount,staticCount,allocCount;
- MVArgT defPos;
- MVOpCode opCode;
- MSConfig confPar;
- short progNum=_MSPRG01;
-
-
- theMSH=MSGetMSH(menuID,progNum);
- HLock(theMSH);
- theMSP=*theMSH;
- theMF=*theMSP->MVT;
- confPar=MSInit(1);
-
- /* Get Menus */
- if (NOT (theMSP->MH=GetMenu(menuID)) )
- MSErrExit(progNum,_MSERR02,menuID,0);
-
- /* Load System resources */
- if (BitTst(&theMF, _MFSYSLOD))
- AddResMenu(theMSP->MH,theMSP->sysRes);
-
- dynamCount=CountMItems(theMSP->MH);
- staticCount=theMSP->staticCount;
- allocCount=theMSP->allocCount;
-
- /* Trim to allocCount */
- IF (BitTst(&theMF, _MFERRTRM))
- THEN
- IF (dynamCount GT allocCount)
- THEN
- /* NOT IMPLEMENTED - Put up Alert informing
- User that such and such a menu was trimmed */
- ENDIF
- ENDIF
- WHILE (dynamCount GT allocCount)
- DelMenuItem(theMSP->MH,dynamCount);
- dynamCount--;
- ENDWHILE
-
- /* Minimal validation */
- if (confPar.dbgFlg)
- MSValidation(theMSH,menuID,staticCount,allocCount);
-
-
- /* If Text toggled, make sure STR# exists */
- IF (BitTst(&theMF, _MFHASSTR))
- THEN
- if (NOT GetResource(_MSSTRTYP,theMSP->ttgStrID) )
- MSErrExit(progNum,_MSERR07,menuID,0);
-
- /* Set STR# Indx for defaulted TXTTOG types */
- j=NULL;
- FOR (i=1;i LE allocCount;i++)
- opCode=theMSP->MVT[i].opCode;
- IF (opCode EQ _MVTEXTOG OR opCode EQ _MVTTGSET)
- THEN
- if (theMSP->MVT[i].argT[3] LE NULL)
- theMSP->MVT[i].argT[3]=j*2+1;
- j++;
- /* Set TXTOG items to TF state */
- theMV.opCode=theMSP->MVT[i].opCode;
- theMSP->MVT[i].opCode=_MVTEXTOG;
- MSTogBit(menuID,i);
- MSDispatch1(theMSP,menuID,i);
- theMSP->MVT[i].opCode=theMV.opCode;
- ENDIF
- ENDFOR
-
- ENDIF
-
- /* Expand Range for added resources */
- IF (BitTst(&theMF, _MFEXPRNG))
- THEN theMV=theMSP->MVT[staticCount];
- if (theMV.opCode NE _MVNZEXRG)
- MSErrExit(progNum,_MSERR09,menuID,staticCount);
- IF (theMV.argT[0] LE NULL)
- THEN theMV.argT[0]=staticCount;
- theMV.argT[1]=dynamCount;
- if (theMV.argT[3])
- theMV.argT[3]+=staticCount-1;
- ENDIF
- for (i=theMV.argT[0];i LE theMV.argT[1];i++)
- theMSP->MVT[i]=theMV;
- ENDIF
-
- /* Allocate MIVT (Menu Item Values Table*/
- if (BitTst(&theMF, _MFALOCTB))
- if (NOT (theMSP->MIVTH=(long **)NewHandle((allocCount+1)*sizeof(long))) )
- MSErrExit(progNum,_MSERR03,menuID,0);
- else
- for (i=NULL;i LE allocCount;i++)
- *((*theMSP->MIVTH)+i)=theMSP->MIVTnullVal;
-
-
- /* MIVT Prep */
- IF (MIVTFct1)
- THEN
- theMSP->procID[0]=MIVTFct1;
- BitSet(theMSP->MVT, _MFPRCFLG);
- ENDIF
- IF (MIVTFct2)
- THEN
- theMSP->procID[1]=MIVTFct2;
- BitSet(theMSP->MVT, _MFPRCFLG+1);
- ENDIF
-
- /* Build MIVT (Menu Item Values Table*/
- if (BitTst(&theMF, _MFBLDTAB))
- if (NOT theMSP->procID[0])
- MSErrExit(progNum,_MSERR10,menuID,0);
- else
- MSCallProc (theMSP,menuID,0,0);
-
- /* Set Menu and TogFlgs for expanded range */
- IF (BitTst(&theMF, _MFSETXRG))
- THEN if (NOT(BitTst(&theMF, _MFEXPRNG)))
- MSErrExit(progNum,_MSERR06,menuID,0);
- defPos=theMV.argT[3];
- IF (NOT defPos)
- THEN defVal=theMSP->MIVTdefVal;
- defPos=staticCount;
- if (defVal)
- for (i=defPos;i LE dynamCount;i++)
- IF (defVal EQ MSGetMIVT(menuID,i))
- THEN defPos=i;
- break;
- ENDIF
- ENDIF
- CheckItem(theMSP->MH,defPos,TRUE);
- MSTogBit(menuID,defPos);
- ENDIF
-
- /* Set Menu and TogFlgs to PREVious state */
- IF (BitTst(&theMF, _MFSETPRE))
- THEN if ( NOT (theHdl=GetResource(_MSPRVTYP,menuID)) )
- MSErrExit(progNum,_MSERR12,menuID,0);
- HLock(theHdl);
- MSAdjTog(menuID,*theHdl,*theHdl+sizeof(ToggleFlag));
- HUnlock(theHdl);
- ENDIF
- /* Execute PROC2 if attached */
- MSCallProc (theMSP,menuID,0,1);
- HUnlock(theMSH);
- return ((int)theMSP->MH);
-
- END_FCT
- //============================
- MSDispatch(menuID, itemNumber)
- short menuID;
- short itemNumber;
- //============================
- BEGIN_FCT
- MSHdl theMSH;
- MSPtr theMSP;
- short progNum=_MSPRG02;
- int MIVTFct1;
- Handle theHandle;
-
- if ( NOT (theMSH=(MSHdl)GetResource(_MSMSTTYP,menuID)) )
- return; /* Don't do anything for non-MST menus */
- HLock(theMSH);
- theMSP=*theMSH;
- MSDispatch1(theMSP,menuID, itemNumber);
- MSCallProc (theMSP,menuID,itemNumber,1);
- HUnlock(theMSH);
-
- END_FCT
- //============================
- MSDispatch1(theMSP,menuID, itemNumber)
- MSPtr theMSP;
- short menuID;
- short itemNumber;
- //============================
- BEGIN_FCT
- MenuHandle theMH;
- MenuVerb theMV;
- MVOpCode opCode;
- MVArgT first, last, parent, other;
- short progNum=_MSPRG03;
- Str255 theSTR;
- int theTVal, flag,i;
-
- if (itemNumber GT theMSP->allocCount)
- return;
- theMH=theMSP->MH;
- theMV=theMSP->MVT[itemNumber];
- opCode=theMV.opCode;
-
- if (opCode LE _MVNORMAL)
- return;
- if (itemNumber GT theMSP->allocCount)
- MSErrExit(progNum,_MSERR17,menuID,itemNumber);
-
- first=theMV.argT[0];
- last=theMV.argT[1];
- parent=theMV.argT[2];
- other=theMV.argT[3];
-
- theTVal=MSTogBit(menuID,itemNumber);
- MSDispatch2(theMSP,menuID,itemNumber,opCode,&first,&last,&parent,&other)
- SWIT (opCode)
- CASE (_MVCHKTOG)
- CheckItem(theMH,itemNumber,theTVal);
- ENDCASE
- CASE (_MVTEXTOG)
- IF (MSGetIndStr(&theSTR,menuID, other+theTVal) LT NULL)
- THEN MSErrExit(progNum,_MSERR08,menuID,itemNumber);
- ELSE SetItem(theMH,itemNumber,&theSTR);
- ENDIF
- ENDCASE
- CASE (_MVENABPR)
- MSTogBit(menuID,other);
- MSEnable(theMH,itemNumber,theTVal);
- MSEnable(theMH,other,NOT theTVal);
- ENDCASE
- CASE (_MVNZEXRG)
- MSClear(theMSP,first,last,opCode);
- CheckItem(theMH,itemNumber,TRUE);
- MSTogBit(menuID, itemNumber);
- ENDCASE
- CASE (_MVCMRGRS)
- SWIT (itemNumber EQ parent)
- CASE(TRUE) /* Parent */
- IF (NOT theTVal)
- THEN MSTogBit(menuID,itemNumber);
- ELSE MSClear(theMSP,first,last,opCode);
- CheckItem(theMH,itemNumber,TRUE);
- IF ((itemNumber GE first) AND (itemNumber LE last))
- THEN MSTogBit(menuID,itemNumber); ENDIF
- ENDIF
- ENDCASE
- CASE (FALSE) /* Member */
- CheckItem(theMH,itemNumber,theTVal);
- IF (theTVal)
- THEN flag=BitTst(&theMSP->TF,parent)
- ELSE flag = NOT MSBitOr(theMSP,first,last,opCode);
- ENDIF
- IF (flag)
- THEN CheckItem(theMH,parent,NOT theTVal);
- MSTogBit(menuID,parent);
- ENDIF
- ENDCASE
- ENDSWIT
- ENDCASE
- CASE (_MVENBSET)
- IF (itemNumber NE parent)
- THEN MSTogBit(menuID,itemNumber);
- ELSE FOR (i=first;i LE last; i++)
- IF (theMSP->MVT[i].opCode EQ opCode)
- THEN
- MSEnable(theMH,i,theTVal);
- MSTogBit(menuID,i);
- ENDIF
- ENDFOR
- if ((itemNumber GE first) AND (itemNumber LE last))
- MSTogBit(menuID,itemNumber);
- else
- MSEnable(theMH,itemNumber, theTVal);
- itemNumber=other;
- if (MSGetTog(menuID,itemNumber) EQ theTVal)
- MSDispatch1(theMSP ,menuID,itemNumber)
- ENDIF
- ENDCASE
- CASE (_MVTTGSET)
- IF (itemNumber NE parent)
- THEN MSTogBit(menuID,itemNumber);
- ELSE FOR (i=first;i LE last; i++)
- IF (theMSP->MVT[i].opCode EQ opCode)
- THEN
- IF (NIL GT MSGetIndStr(&theSTR,
- menuID,theMSP->MVT[i].argT[3]+theTVal))
- THEN MSErrExit(progNum,_MSERR08,menuID,i);
- ELSE SetItem(theMH,i,&theSTR);
- MSTogBit(menuID,i);
- ENDIF
- ENDIF
- ENDFOR
- IF ((itemNumber GE first) AND (itemNumber LE last))
- THEN MSTogBit(menuID,itemNumber);
- ELSE IF (NIL GT MSGetIndStr(&theSTR,
- menuID,other+theTVal))
- THEN MSErrExit(progNum,_MSERR08,menuID,itemNumber);
- ELSE SetItem(theMH,itemNumber,&theSTR);
- ENDIF
- ENDIF
- ENDIF
- ENDCASE
- ENDSWIT
-
- END_FCT
- //================================================
- MSDispatch2(theMSP,menuID,itemNumber,opCode,first,last,parent,other)
- MSPtr theMSP;
- short menuID,itemNumber;
- MVOpCode opCode;
- MVArgT *first,*last,*parent,*other;
- //================================================
- /* default Parser */
- BEGIN_FCT
- int i,j;
- MenuVerb fakeVerb;
- short dynamCount;
- short progNum=_MSPRG11;
-
- dynamCount=CountMItems(theMSP->MH);
- SWIT (opCode)
- CASE (_MVENABPR)
- if (*other LE NULL)
- *other=itemNumber+(*other?-1:1);
- ENDCASE
- CASE (_MVNZEXRG)
- CASE (_MVCMRGRS)
- CASE (_MVENBSET)
- CASE (_MVTTGSET)
- if (*first AND *last)
- return;
- else
- if (*first OR *last)
- MSErrExit(progNum,_MSERR14,menuID,itemNumber);
-
- for (i=itemNumber;i GT NULL;i--)
- if (theMSP->MVT[i].opCode EQ _MVMENLIN)
- break;
- for (j=itemNumber;j LE dynamCount;j++)
- if (theMSP->MVT[j].opCode EQ _MVMENLIN)
- break;
-
- *first=++i;
- *last=--j;
- if (opCode EQ _MVNZEXRG)
- break;
- IF (*parent LE NULL)
- THEN
- *parent=*first;
- ELSE
- *parent+=*first-1;
- if (*parent LT *first OR *parent GT *last)
- MSErrExit(progNum,_MSERR16,menuID,itemNumber);
- ENDIF
- if (opCode NE _MVENBSET)
- break;
- if (*other GT NULL)
- break;
- itemNumber=(*other)?*first-2:*last+2;
- if (itemNumber LE NULL OR itemNumber GT dynamCount)
- MSErrExit(progNum,_MSERR15,menuID,itemNumber);
- for (i=NULL;i LT _MVARGDIM;i++)
- fakeVerb.argT[i]=theMSP->MVT[itemNumber].argT[i];
- MSDispatch2(theMSP,menuID,itemNumber,_MVCMRGRS,
- &fakeVerb.argT[0],&fakeVerb.argT[1],
- &fakeVerb.argT[2],&fakeVerb.argT[3]);
- *other=fakeVerb.argT[2];
- ENDCASE
- ENDSWIT
-
- END_FCT
- //==============================================
- int MSInsMenuItem(menuID,menuStr,after,theMV)
- short menuID;
- char *menuStr;
- short after;
- MenuVerb *theMV;
- //==============================================
- BEGIN_FCT
- short progNum=_MSPRG12;
- short staticCount, dynamicCount,allocCount;
- MSHdl theMSH;
- MSPtr theMSP;
- long menLineTxt=0x02282D00; /* (- pascal string */
-
- theMSH=MSGetMSH(menuID,progNum);
- HLock(theMSH);
- theMSP=*theMSH;
- MSParseAfter(theMSP,&after,&staticCount,&dynamicCount,&allocCount);
-
- if (dynamicCount GE allocCount)
- return (-_MSERR17); /* dynamicCount GE allocCount */
- SWIT (theMV->opCode)
- CASE (_MVTEXTOG)
- CASE (_MVTTGSET)
- return (-_MSERR24); /* not implemented */
- ENDCASE
- ENDSWIT
- MSShift(theMSP,after,1);
- theMSP->MVT[after+1] = *theMV;
- if (theMV->opCode EQ _MVMENLIN)
- menuStr=(char *)(&menLineTxt);
- InsMenuItem(theMSP->MH,menuStr,after);
-
- HUnlock(theMSH);
- return (after+1);
-
-
- END_FCT
- //=========================
- MSDelMenuItem(menuID,itemNumber)
- short menuID;
- short itemNumber;
- //=========================
- BEGIN_FCT
- short progNum=_MSPRG13;
- short staticCount, dynamicCount,allocCount;
- MSHdl theMSH;
- MSPtr theMSP;
-
- theMSH=MSGetMSH(menuID,progNum);
- HLock(theMSH);
- theMSP=*theMSH;
-
- MSParseAfter(theMSP,&itemNumber,&staticCount,&dynamicCount,&allocCount);
- if (itemNumber EQ staticCount)
- if (staticCount EQ dynamicCount)
- return (-_MSERR17);
- else
- itemNumber++;
- MSShift(theMSP,itemNumber,-1);
- DelMenuItem(theMSP->MH,itemNumber);
-
- HUnlock(theMSH);
- return (NULL);
-
-
- END_FCT
- //=========================================
- MSParseAfter(theMSP,after,staticCount,dynamicCount,allocCount)
- MSPtr theMSP;
- short *after,*staticCount,*dynamicCount,*allocCount;
- //=========================================
- BEGIN_FCT
- short offset=0;
- MSConfig theConfig;
-
- *dynamicCount=CountMItems(theMSP->MH);
- *staticCount=theMSP->staticCount;
- *allocCount=theMSP->allocCount;
-
- theConfig=MSInit(1);
- if (theConfig.relFlg)
- offset=*staticCount;
-
- *after+=offset;
- if (*after LE *staticCount)
- *after=*staticCount;
- else
- if (*after GE *dynamicCount)
- *after=*dynamicCount;
-
-
- END_FCT
- //=========================
- MSShift(theMSP,itemNumber,direction)
- MSPtr theMSP;
- short itemNumber, direction;
- //=========================
- BEGIN_FCT
- short progNum=_MSPRG14;
- MenuVerb *MVTP;
- long *MIVTP;
- ToggleFlag *TFP;
- int i,k,first,last,dynamicCount;
-
- /*
- insert delete
- dir=+1 Δ=-1 dir=-1 Δ=+1
- ----- -----
- last √----- ^ first ^----- |
- √----- | ^----- √
- √----- ^-----
- first ----- i-- last ----- i++
-
- in all cases T[i]=T[i+Δ]
-
- */
-
- MVTP=theMSP->MVT;
- TFP=&theMSP->TF;
- dynamicCount=CountMItems(theMSP->MH);
- if (BitTst(theMSP->MVT, _MFALOCTB))
- MIVTP=(*theMSP->MIVTH);
- else
- MIVTP=NIL;
-
- IF (direction GT NULL)
- THEN /* Insert */
- first=dynamicCount+1;
- last=itemNumber+1;
- ELSE /* Delete */
- first=itemNumber;
- last=dynamicCount;
- ENDIF
- direction*=-1;
-
- FOR (i=first;i-last;i+=direction)
- *(MVTP+i)=*(MVTP+i+direction);
- k=BitTst(TFP,i+direction);
- if (k)
- BitSet(TFP,i);
- else
- BitClr(TFP,i);
- if (MIVTP)
- *(MIVTP+i)=*(MIVTP+i+direction);
- ENDFOR
-
- /* NULL value problems here */
- for (i=0;i LT _MVARGDIM;i++)
- *((char *)(MVTP+last)+i)='\0';
- if (MIVTP)
- *(MIVTP+last)=theMSP->MIVTnullVal;
- BitClr(TFP,last);
-
- END_FCT
-
- //=====================
- MSInsert(menuID, beforeID)
- short menuID,beforeID;
- //=======================
- BEGIN_FCT
- MSHdl theMSH;
- MenuHandle theMH;
- short progNum=_MSPRG04;
-
- theMSH=MSGetMSH(menuID,progNum);
- HLock(theMSH);
- theMH=(*theMSH)->MH;
- if (NOT theMH)
- MSErrExit(progNum,_MSERR02,menuID,0);
- if (BitTst((*theMSH)->MVT, _MFSUBMEN))
- InsertMenu(theMH,-1);
- else if (beforeID NE NULL)
- InsertMenu(theMH,beforeID);
- else
- InsertMenu(theMH,(*theMSH)->beforeID);
-
- HUnlock(theMSH);
-
- END_FCT
- //=================
- MSDelete(menuID)
- short menuID;
- //=================
- BEGIN_FCT
- DeleteMenu(menuID);
- END_FCT
- //=====================
- MSDispose(menuID)
- short menuID;
- //=======================
- BEGIN_FCT
- MSHdl theMSH;
- MSPtr theMSP;
- short progNum=_MSPRG05;
-
- theMSH=MSGetMSH(menuID,progNum);
- HLock(theMSH);
-
- theMSP=*theMSH;
- DisposeMenu(theMSP->MH);
- ReleaseResource(theMSP->MH);
- if (BitTst(theMSP->MVT, _MFALOCTB))
- DisposHandle(theMSP->MIVTH );
-
- HUnlock(theMSH);
- ReleaseResource(theMSH);
-
- END_FCT
- //=========================
- int MSGetTog(menuID,itemNumber)
- short menuID;
- short itemNumber;
- //=======================
- BEGIN_FCT
- MSHdl theMSH;
- MSPtr theMSP;
- Handle theHdl;
- short progNum=_MSPRG06;
-
- theMSH=MSGetMSH(menuID,progNum);
- return(BitTst(&(*theMSH)->TF,itemNumber));
-
- END_FCT
- //=========================
- int MSGetMIVT(menuID,itemNumber)
- short menuID, itemNumber;
- //=======================
- BEGIN_FCT
- MSHdl theMSH;
- MSPtr theMSP;
- short progNum=_MSPRG07;
-
- theMSH=MSGetMSH(menuID,progNum);
- theMSP=*theMSH;
- if (itemNumber GT theMSP->allocCount)
- MSErrExit(progNum,_MSERR17,menuID,itemNumber);
-
- return (*((*theMSP->MIVTH)+itemNumber));
-
- END_FCT
- //=========================
- MSSetMIVT(menuID,itemNumber,value)
- short menuID, itemNumber;
- long value;
- //=======================
- BEGIN_FCT
- MSHdl theMSH;
- MSPtr theMSP;
- short progNum=_MSPRG07;
-
- theMSH=MSGetMSH(menuID,progNum);
- theMSP=*theMSH;
- if (itemNumber GT theMSP->allocCount)
- MSErrExit(progNum,_MSERR17,menuID,itemNumber);
- *((*theMSP->MIVTH)+itemNumber)=value;
-
- END_FCT
- //=========================
- int MSFindMIVT(menuID,first,last,theMIVT)
- short menuID,first,last;
- long theMIVT;
- //=======================
- BEGIN_FCT
- short progNum=_MSPRG15;
- MSHdl theMSH;
- long *theMIVTP;
- int i,allocCount;
-
-
- theMSH=MSGetMSH(menuID,progNum);
- if (NOT BitTst((*theMSH)->MVT, _MFALOCTB))
- return (-1);
- theMIVTP=(*(*theMSH)->MIVTH);
- allocCount=(*theMSH)->allocCount;
- first=(first LT 1)?1:first;
- last=(last GT allocCount)?allocCount:last;
- for (i=first;i LE last; i++)
- if (*(theMIVTP+i) EQ theMIVT)
- return (i);
- return (NULL)
-
- END_FCT
- //=========================
- MSAdjTog(menuID,theTF,theMSK)
- short menuID;
- ToggleFlag *theTF,*theMSK;
- //=======================
- BEGIN_FCT
- MSHdl theMSH;
- MSPtr theMSP;
- short progNum=_MSPRG08;
- int i;
- short allocCount;
-
- theMSH=MSGetMSH(menuID,progNum);
- HLock(theMSH);
- theMSP=*theMSH;
- allocCount=(*theMSH)->allocCount;
- for (i=1; i LE allocCount;i++)
- if (BitTst(theMSK,i))
- IF ( BitTst(&(*theMSH)->TF,i)
- NE BitTst(theTF,i) )
- THEN
- MSDispatch1(theMSP,menuID,i);
- MSCallProc (theMSP,menuID,i,1);
- ENDIF
-
- HUnlock(theMSH);
-
- END_FCT
- //=========================
- MSAdjPREV(menuID)
- short menuID;
- //=======================
- BEGIN_FCT
- MSHdl theMSH;
- Handle thePREVH;
- Ptr thePREVP;
- short progNum=_MSPRG10;
- int i;
- short theErr,allocCount;
-
- theMSH=MSGetMSH(menuID,progNum);
- if ( NOT (thePREVH=GetResource(_MSPRVTYP,menuID)) )
- MSErrExit(progNum,_MSERR12,menuID,0);
- allocCount=(*theMSH)->allocCount;
- HLock(thePREVH);
- thePREVP=*thePREVH;
-
- for (i=1; i LE allocCount;i++)
- if (BitTst(thePREVP+sizeof(ToggleFlag),i))
- if ( BitTst(&(*theMSH)->TF,i)
- NE BitTst(thePREVP,i) )
- if (BitTst(&(*theMSH)->TF,i))
- BitSet(thePREVP,i);
- else
- BitClr(thePREVP,i);
-
- ChangedResData(thePREVH);
- if (theErr=ResError())
- MSErrExit(progNum,_MSERR13,menuID,theErr);
- WriteResource(thePREVH);
- if (theErr=ResError())
- MSErrExit(progNum,_MSERR13,menuID,theErr);
- HUnlock(thePREVH);
- ReleaseResource(thePREVH);
-
- END_FCT
- //=========================
- MSHdl MSGetMSH(menuID,progNum)
- short menuID;
- short progNum;
- //=======================
- BEGIN_FCT
- MSHdl theMSH;
- if ( NOT (theMSH=(MSHdl)GetResource(_MSMSTTYP,menuID)) )
- MSErrExit(progNum,_MSERR01,menuID,0);
- return (theMSH );
-
-
- END_FCT
- //=================
- int MSTogBit(menuID,itemNumber)
- short menuID;
- short itemNumber;
- //================
- /*_______ toggles and returns current value ________*/
- BEGIN_FCT
- MSHdl theMSH;
- MSPtr theMSP;
- short progNum=_MSPRG09;
-
- theMSH=MSGetMSH(menuID,progNum);
- theMSP=*theMSH;
- if (itemNumber GT theMSP->allocCount)
- MSErrExit(progNum,_MSERR17,menuID,itemNumber);
-
- IF (BitTst(&theMSP->TF,itemNumber))
- THEN BitClr(&theMSP->TF,itemNumber);
- return(FALSE);
- ELSE BitSet(&theMSP->TF,itemNumber);
- return(TRUE);
- ENDIF
-
- END_FCT
- //=================
- int MSGetIndStr(theStrP,menuID,strIndx)
- char *theStrP;
- short menuID,strIndx;
- //=================
- BEGIN_FCT
- MSHdl theMSH;
- short progNum=_MSPRG19;
-
-
- theMSH=MSGetMSH(menuID,progNum);
- menuID=(*theMSH)->ttgStrID;
- return (fGetIndStr(theStrP,menuID,strIndx));
-
- END_FCT
- //=================
- int fGetIndStr(theStrP,strID,strIndx)
- char *theStrP;
- short strID,strIndx;
- //=================
- /* Like NOT IN ROM GetIndStr, except returns length,
- or -1 if Indx out of bounds */
- BEGIN_FCT
- Handle theSTRH;
- short i,j;
- short maxIndx;
- long len;
- char *s;
-
- if ( NOT (theSTRH=GetResource(_MSSTRTYP,strID)) )
- return (-1);
- maxIndx=*((short *)(*theSTRH));
- if ((strIndx GT maxIndx) OR (strIndx LE NULL))
- return (-1);
-
- s=*theSTRH + sizeof(short);
- for (i=1; i LT strIndx; i++)
- s+=(unsigned char)(*s)+1;
-
- len=(unsigned char)(*s)+1;
- *theStrP=NULL;
- BlockMove(s,theStrP,len);
- return(len);
-
- END_FCT
-
- //=========================
- MSErrExit(progName,errNum,menuID,itemNum)
- short progName,errNum,menuID,itemNum;
- //=======================
- BEGIN_FCT
- Handle theHdl;
- Str255 paramTxt[4],sjunk;
- int i;
- short separator=0x012F; /* "/" with length byte */
- short len;
- char *s;
- MSConfig confg;
-
- confg=MSInit(1);
- for (i=NULL;i LT 4;i++)
- paramTxt[i].count=NULL;
- IF ((theHdl=GetResource('ALRT',confg.alrtID)) EQ NULL
- OR GetResource('DITL',confg.alrtID) EQ NULL)
- THEN
- SysBeep(30);
- SysBeep(30);
- SysBeep(30);
- ExitToShell();
- ENDIF
-
- IF (confg.dbgFlg)
- THEN
- fGetIndStr(¶mTxt[0],confg.errStrID,_MSERR23);
- theHdl=GetResource('DITL',confg.alrtID);
- s=*theHdl+2;
- s+=13;
- len=*s;
- s+=len+1;
- s+=13;
- len=*s;
- for (i=1; i LE len;i++)
- *(s+i)=paramTxt[0].s[i-1];
-
- MSErrExit1(¶mTxt[0],progName,confg.prgStrID,confg.altPrgStrID);
- MSErrExit1(¶mTxt[1],errNum,confg.errStrID,confg.altErrStrID);
-
- NumToString(menuID,¶mTxt[2]);
- MSPcat(¶mTxt[2],&separator);
- NumToString(itemNum,¶mTxt[3]);
- MSPcat(¶mTxt[2],¶mTxt[3]);
- paramTxt[3].count=NULL;
- ENDIF
-
- ParamText(¶mTxt[0],¶mTxt[1],¶mTxt[2],¶mTxt[3]);
- IF (StopAlert(confg.alrtID,NIL) EQ oK)
- THEN
- ExitToShell();
- ELSE
- IF (NOT confg.dbgFlg)
- THEN
- #asm
- RESET
- #endasm
- ELSE
- return;
- ENDIF
- ENDIF
-
-
- END_FCT
- //=======================================
- MSErrExit1(paramStr,strNum,strID,altStrID)
- Str255 *paramStr;
- short strNum,strID,altStrID;
- //=======================================
- BEGIN_FCT
- Handle theHdl;
-
-
- if ( (theHdl=GetResource(_MSSTRTYP,strID)) NE NULL )
- if (fGetIndStr(paramStr,strID,strNum) GE NULL)
- return;
-
- if (altStrID GE NULL)
- if ( (theHdl=GetResource(_MSSTRTYP,altStrID)) NE NULL )
- if (fGetIndStr(paramStr,altStrID,-strNum) GE NULL)
- return;
-
- NumToString(strNum,paramStr);
-
-
- END_FCT
- /*________________________ STATIC FCTS _______________________________*/
- //==================================================
- MSValidation (theMSH, menuID,staticCount,allocCount)
- MSHdl theMSH;
- short menuID,staticCount,allocCount;
- //==================================================
- BEGIN_FCT
- MSPtr theMSP;
- int i,byteOffSet,HandleSize;
- short progNum=_MSPRG20;
-
- theMSP=*theMSH;
-
- if (staticCount GT allocCount)
- MSErrExit(progNum,_MSERR18,menuID,0);
- byteOffSet=_MSFIXLEN+(allocCount+1)*sizeof(MenuVerb);
- HandleSize=GetHandleSize(theMSH);
- IF (BitTst(theMSP->MVT,_MFPRCPAR))
- THEN
- i=*((short *)((char *)theMSP+byteOffSet));
- byteOffSet+=(i+1)*sizeof(short);
- ENDIF
- if (byteOffSet NE HandleSize)
- MSErrExit(progNum,_MSERR22,menuID,0);
-
-
- FOR (i=1;i LE allocCount;i++)
- SWIT (theMSP->MVT[i].opCode)
- CASE (_MVNORMAL)
- CASE (_MVMENLIN)
- if (BitTst(&theMSP->TF,i))
- MSErrExit(progNum,_MSERR19,menuID,i);
- ENDCASE
- CASE (_MVCHKTOG)
- CASE (_MVTEXTOG)
- CASE (_MVENABPR)
- CASE (_MVNZEXRG)
- CASE (_MVCMRGRS)
- CASE (_MVENBSET)
- CASE (_MVTTGSET)
- ENDCASE
- DEFCASE
- MSErrExit(progNum,_MSERR20,menuID,i);
- ENDCASE
- ENDSWIT
- ENDFOR
- FOR (i=staticCount+1;i LE _TFBITSZE;i++)
- if (BitTst(&theMSP->TF,i))
- MSErrExit(progNum,_MSERR21,menuID,i);
- ENDFOR
-
-
- END_FCT
-
- //============================
- static MSEnable(theMH,itemNumber,flag)
- MenuHandle theMH;
- short itemNumber;
- short flag;
- //============================
- BEGIN_FCT
- IF (flag)
- THEN EnableItem(theMH,itemNumber);
- ELSE DisableItem(theMH,itemNumber);
- ENDIF
-
- END_FCT
- //=================
- static MSClear(theMSP,first, last,opCode)
- MenuStuff *theMSP;
- short first,last;
- MVOpCode opCode;
- //=================
- /* Clears all bits in range
- Unchecks any Checked menu items in range */
- BEGIN_FCT
- short i,theMark;
-
- FOR(i=first;i LE last;i++)
- IF (theMSP->MVT[i].opCode EQ opCode)
- THEN
- BitClr(&theMSP->TF,i);
- GetItemMark(theMSP->MH,i,&theMark);
- if (theMark NE noMark)
- CheckItem(theMSP->MH,i,FALSE);
- ENDIF
- ENDFOR
-
-
- END_FCT
- //=================
- static int MSBitOr(theMSP,first, last,opCode)
- MSPtr theMSP;
- short first,last;
- MVOpCode opCode;
- //=================
- /*_______ returns (i..j) togbit k ________*/
- BEGIN_FCT
- short i;
-
- for (i=first;i LE last;i++)
- if (theMSP->MVT[i].opCode EQ opCode)
- if (BitTst(&theMSP->TF,i))
- return(TRUE);
-
- return(FALSE);
-
-
- END_FCT
- //===========
- MSPcat(s1,s2)
- char *s1,*s2;
- //===========
- BEGIN_FCT
- int i;
-
- BlockMove(s2+1,s1+*s1+1,*s2);
- *s1+=*s2;
-
- END_FCT
- //====================================
- static MSCallProc (theMSP,menuID,itemNumber,indx)
- MSPtr theMSP;
- short menuID,itemNumber,indx;
- //====================================
- BEGIN_FCT
- int MIVTFct;
- Handle theHdl;
- int retVal;
- Str255 theStr;
- MSConfig confg;
- short progNum=_MSPRG16;
-
- if (NOT theMSP->procID[indx])
- return;
-
- MIVTFct=theMSP->procID[indx];
- IF (NOT BitTst(theMSP->MVT, _MFPRCFLG+indx))
- THEN IF (NOT (theHdl=GetResource(_MSPRCTYP,MIVTFct)) )
- THEN MSErrExit(progNum,_MSERR04,menuID,indx+1);
- ELSE HLock(theHdl);
- MIVTFct=(int)(*theHdl);
- ENDIF
- ENDIF
- retVal=(*((int (*)())(MIVTFct)))(theMSP ,menuID,itemNumber,indx);
- IF (retVal NE _MSMIVTOK)
- THEN confg=MSInit(1);
- if (confg.dbgFlg OR retVal LE _MSMIVTER)
- MSErrExit(progNum,_MSERR05,menuID,(-retVal*256)+indx);
- ENDIF
- if (NOT BitTst(theMSP->MVT, _MFPRCFLG+indx))
- HUnlock(theHdl);
-
- END_FCT
-
-
-